from selenium import webdriver
from selenium.webdriver.edge.service import Service

from automatic import page

class GetDriver:
    driver=None

    #获取driver
    @classmethod
    def get_driver(cls):
        if cls.driver is None:
            service = Service(executable_path='E:\pycharm\code\project1\.venv\msedgedriver.exe')
            service.start()  # 预先启动服务（单例模式）
            cls.driver=webdriver.Edge()
            #最大化浏览器
            cls.driver.maximize_window()
            #打开url
            cls.driver.get(page.URL)
        #返回driver
        return cls.driver

    #关闭driver
    @classmethod
    def quit_driver(cls):
        if cls.driver:
            cls.driver.quit()
            #必须置空操作
            cls.driver=None

if __name__ == '__main__':
    GetDriver().quit_driver()